package com.yeeKa.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.yeeKa.common.enums.BusinessType;
import com.yeeKa.domain.Lock1518;
import com.yeeKa.domain.Order;
import com.yeeKa.domain.Product;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;
import com.yeeKa.common.annotation.Log;
import com.yeeKa.common.core.controller.BaseController;
import com.yeeKa.common.core.domain.AjaxResult;
import com.yeeKa.domain.SaleTable;
import com.yeeKa.service.InterlockingRecordsService;
import com.yeeKa.utils.poi.ExcelUtil;
import com.yeeKa.common.core.page.TableDataInfo;

/**
 * 销售单Controller
 * 
 * @author ruoyi
 * @date 2023-09-04
 */
@RestController
@RequestMapping("/locking")
@Api(tags = "锁记录")
public class InterlockingRecordsController extends BaseController
{
    /*
        //todo 获取OA中   物联锁订单列表
        //todo 入参工号   出参:权限未通过信息:订单列表

        //根据物联锁订单号,获取ERP中订单的锁数量,以及订单信息

        //根据锁型号获取测试标准

        //todo 根据锁SN信息获取测试记录

        //新增测试记录(一种型号一张表)
     */
    @Resource
    private InterlockingRecordsService interlockingRecordsService;

    /**
     * 根据订单号获取订单信息"/{orderNo}
     *
     */
    @GetMapping("/getOrderList")
    public TableDataInfo getOrderList(@RequestParam()String salNo)
    {
        List<Order> list = interlockingRecordsService.selectOrderList(salNo);
        return getDataTable(list);
    }

    /**
     * 根据订单号获取订单信息"/{orderNo}
     *
     */
    @GetMapping("/getListByOrder")
    public TableDataInfo getListByOrder(@RequestParam()String orderNo ,String moder)
    {
        Product product = new Product();
        product.setOrderNo(orderNo);
        product.setModer(moder);
        List<Product> list = interlockingRecordsService.selectProductList(product);
        return getDataTable(list);
    }

    /**
     * 根据锁类型获取项目标准信息
     */
    @GetMapping("/getListByModer")
    public TableDataInfo getListByModer(@RequestParam()String moder)
    {
        List<Object> mapList = interlockingRecordsService.selectMapByModel(moder);
        return getDataTable(mapList);
    }

    /**
     * 根据锁类型获取项目标准信息
     */
    @GetMapping("/getListByModer2")
    public TableDataInfo getListByModer2(@RequestParam()String moder)
    {
        List<Object> mapList = interlockingRecordsService.selectMapByModel2(moder);
        return getDataTable(mapList);
    }

    /**
     * 新增测试记录
     */
    @Log(title = "测试记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Lock1518 lock1518)
    {
        return toAjax(interlockingRecordsService.insertLock1518(lock1518));
    }

    /**
     * 查询测试记录单
     */
    @GetMapping("/getRecords")
    public TableDataInfo getRecords(String sn,String orderNo,String englishName)
    {
        List<Lock1518> list = interlockingRecordsService.getRecords(sn,orderNo,englishName);
        return getDataTable(list);
    }

    /**
     * 导出测试记录列表
     */
//    @PreAuthorize("@ss.hasPermi('system:table:export')")
    @Log(title = "销售单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SaleTable saleTable)
    {
        List<SaleTable> list = interlockingRecordsService.selectSaleTableList(saleTable);
        ExcelUtil<SaleTable> util = new ExcelUtil<>(SaleTable.class);
        util.exportExcel(response, list, "销售单数据");
    }

}
